import {
    _ as _export_sfc,
    a as createElementBlock,
    b as createBaseVNode,
    C as reactive,
    d as defineComponent,
    D as withModifiers,
    e as ref,
    E as withKeys,
    g as useRouter,
    G as api,
    o as openBlock,
    p as withCtx,
    q as createVNode,
    s as _sfc_main$3,
    t as toDisplayString,
    u as unref,
    v as createTextVNode,
    x as useAuthStore,
    z as storeToRefs
} from "./index-Dfdf_Rjk.js";
import {_ as _sfc_main$2} from "./SimpleInput.vue_vue_type_script_setup_true_lang-D6HMgtcH.js";
import {_ as _imports_0, a as _sfc_main$1} from "./logo-DPS5-E7_.js";

const _hoisted_1 = {class: "login-wrap relative flex-center flex-col overflow-hidden"};
const _hoisted_2 = {class: "relative h-100 w-100 flex-center flex-col gap-4 rounded-xl bg-base p-8 pb-4 shadow-lg"};
const _hoisted_3 = {class: "flex flex-none flex-col items-center"};
const _hoisted_4 = {class: "relative mt-3 text-center text-1.6rem font-500"};
const _hoisted_5 = {class: "absolute right--15 top-0 rounded bg-blue/20 px2 text-sm text-primary/60 font-[tnum-light] italic"};
const _hoisted_6 = {class: "w-full flex-1"};
const _hoisted_7 = {class: "mt-4 text-sm text-gray-400"};
const _sfc_main = /* @__PURE__ */ defineComponent({
    __name: "index",
    setup(__props) {
        const authStore = useAuthStore();
        const {user} = storeToRefs(authStore);
        const router = useRouter();
        const modelRef = reactive({
            username: "admin",
            password: "111111"
        });
        const loading = ref(false);

        function validate() {
            if (!modelRef.username) {
                api.warning("请输入账号");
                return false;
            }
            if (!modelRef.password) {
                api.warning("请输入密码");
                return false;
            }
            if (modelRef.password !== "123456") {
                api.warning("用户名或密码错误");
                return false;
            }
            return true;
        }

        async function handleSubmit() {
            var _a, _b;
            if (!validate())
                return;
            loading.value = true;
            try {
                const params = {
                    username: modelRef.username,
                    password: modelRef.password
                };
                user.value.username = params.username;
                await router.push(((_b = (_a = router.currentRoute.value) == null ? void 0 : _a.query) == null ? void 0 : _b.redirect) || "/");
                api.success("登录成功！");
            } catch (e) {
                console.log(e);
            } finally {
                loading.value = false;
            }
        }

        const appTitle = "模型及任务管理";
        const appVersion = "1.0.0";
        const appCopyright = "北京计算机技术及应用研究所";
        return (_ctx, _cache) => {
            const _component_GradientText = _sfc_main$1;
            const _component_SimpleInput = _sfc_main$2;
            const _component_SimpleButton = _sfc_main$3;
            return openBlock(), createElementBlock("div", _hoisted_1, [
                createBaseVNode("div", _hoisted_2, [
                    createBaseVNode("div", _hoisted_3, [
                        _cache[3] || (_cache[3] = createBaseVNode("img", {
                            src: _imports_0,
                            width: "60"
                        }, null, -1)),
                        createBaseVNode("div", _hoisted_4, [
                            createVNode(_component_GradientText, {"to-color": "#0065ff44"}, {
                                default: withCtx(() => [
                                    createTextVNode(toDisplayString(unref(appTitle)), 1)
                                ]),
                                _: 1
                            }),
                            createBaseVNode("div", _hoisted_5, " v" + toDisplayString(unref(appVersion)), 1)
                        ])
                    ]),
                    createBaseVNode("div", _hoisted_6, [
                        createBaseVNode("form", {
                            class: "flex flex-col gap-5",
                            onSubmit: _cache[2] || (_cache[2] = withModifiers(() => {
                            }, ["prevent"]))
                        }, [
                            createVNode(_component_SimpleInput, {
                                modelValue: unref(modelRef).username,
                                "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => unref(modelRef).username = $event),
                                class: "py-1.5",
                                maxlength: 64,
                                placeholder: "账号"
                            }, {
                                prefix: withCtx(() => _cache[4] || (_cache[4] = [
                                    createBaseVNode("div", {class: "i-ph:user-duotone text-xl text-gray-400"}, null, -1)
                                ])),
                                _: 1
                            }, 8, ["modelValue"]),
                            createVNode(_component_SimpleInput, {
                                modelValue: unref(modelRef).password,
                                "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => unref(modelRef).password = $event),
                                class: "py-1.5",
                                maxlength: 64,
                                type: "password",
                                placeholder: "密码",
                                onKeyup: withKeys(handleSubmit, ["enter"])
                            }, {
                                prefix: withCtx(() => _cache[5] || (_cache[5] = [
                                    createBaseVNode("div", {class: "i-ph:lock-duotone text-xl text-gray-400"}, null, -1)
                                ])),
                                _: 1
                            }, 8, ["modelValue"]),
                            createVNode(_component_SimpleButton, {
                                type: "primary",
                                class: "mt-2 w-full h-9!",
                                loading: unref(loading),
                                onClick: handleSubmit
                            }, {
                                default: withCtx(() => _cache[6] || (_cache[6] = [
                                    createTextVNode(" 登 录 ")
                                ])),
                                _: 1
                            }, 8, ["loading"])
                        ], 32)
                    ]),
                    createBaseVNode("div", _hoisted_7, toDisplayString((/* @__PURE__ */ new Date()).getFullYear()) + " © " + toDisplayString(unref(appCopyright)), 1)
                ])
            ]);
        };
    }
});
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-327393c4"]]);
export {
    index as default
};
